﻿using System;
using System.IO;
using UnityEditor;
using UnityEngine;

/// <summary>
/// 处理文件夹的工具库
/// </summary>
public static class FolderToolKit
{
    public static void CoutineCheck(string path, Action<string> FileCallback)   //是文件夹，继续向下
    {
        DirectoryInfo directory = new DirectoryInfo(@path);
        FileSystemInfo[] fileSystemInfos = directory.GetFileSystemInfos();

        foreach (var item in fileSystemInfos)
        {
            int idx = item.ToString().LastIndexOf(@"\");//得到最后一个'\'的索引
            string name = item.ToString().Substring(idx + 1);//截取后面的作为名称

            if (!name.Contains(".meta") && !name.Contains("$"))
            {
                CheckFileOrDirectory(item, path + "/" + name, FileCallback);  //item  文件系统，加相对路径
            }
        }
    }

    /// <summary>
    /// //判断是文件还是文件夹
    /// </summary>
    /// <param name="fileSystemInfo"></param>
    /// <param name="path"></param>
    public static void CheckFileOrDirectory(FileSystemInfo fileSystemInfo, string path, Action<string> FileCallback) 
    {
        FileInfo fileInfo = fileSystemInfo as FileInfo;
        if (fileInfo != null)
        {
            FileCallback(path);
        }
        else
        {
            CoutineCheck(path, FileCallback);
        }
    }


}
